using System.Data.Entity.ModelConfiguration;
using PhoneBook.Core.Domain.UserGroups;

namespace PhoneBook.Data.Mapping
{
    public class UserGroupMap : EntityTypeConfiguration<UserGroup>
    {
        public UserGroupMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.GroupName)
                .HasMaxLength(1000);

            // Table & Column Mappings
            this.ToTable("UserGroup");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.GroupName).HasColumnName("GroupName");

            // Relationships
            this.HasMany(t => t.Contacts)
                .WithMany(t => t.UserGroups)
                .Map(m =>
                    {
                        m.ToTable("UserGroupContacts");
                        m.MapLeftKey("UserGroup_Id");
                        m.MapRightKey("Contact_Id");
                    });


        }
    }
}
